//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import memberInfo from '../comm/memberInfo.vue'
import clockItem from '../comm/clockItem.vue'
import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  mixins: [scrollMixin], //加载更多
  //import引入的组件需要注入到对象中才能使用
  components: {
    memberInfo,
    clockItem
  },
  data() {
  return {
    active:0,
    query:{
      page:1,
      admin_type:0,
    },
    actQuery:{
      status:'',
      title:'',
      page:1,
    },
    actIsLoadMore:true,
    memberTab:[
      {
        name:'参与的',
        val:0,
      },
    ],
    totalPage:0,
    actTotalPage:0,
    isLoadMore:true,
    clockList:[],
    activityList:[],
    calendarInfo:{},
    pluginName:'',
    imgPath:'',
    isAdmin:false
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    memberTabOn(event,name) {
      console.log(event);
      if(event == 0 && this.isAdmin) {
        this.query.admin_type = 1;
        this.isLoadMore = true;
        this.activityList = [];
        this.actQuery.page = 1;
        this.activityListData();
      } else {
        this.query.admin_type = 0;
        this.isLoadMore = true;
        this.clockList = [];
        this.query.page = 1;
        this.clockListData();
      }
      
    },
    getMember() {
      $http.get("plugin.check-in-rebate.frontend.participate-in.get-Info", {}, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            let infoMember = {
              priceName:'退回金额（元）',
              priceVal:res.member?.reward_price || '0',
              couponName:'优惠券（张）',
              couponVal:res.member?.coupon_num || '0'
            };
            console.log(res.member);
            this.isAdmin = res.member?.is_admin;
            this.calendarInfo = {...infoMember,...res.member};
            if(res.member?.is_admin) {
              let memberTab = [
                {
                  name:'管理的',
                  val:0,
                },
                {
                  name:'参与的',
                  val:1,
                },
              ];
              this.memberTab = memberTab;
              this.query.admin_type = 1;
              this.$refs.actTab.resize();
              this.actQuery.page = 1;
              this.activityList = [];
              this.activityListData();
            }
            console.log(this.calendarInfo);
          } else {
            
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    activityListData() {
      $http.post("plugin.check-in-rebate.frontend.index.get-base-info", {search:this.actQuery}, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            let {activity,set} = res;
            this.isLoadMore = true;
            this.actTotalPage = activity.last_page;
            if (!this.actTotalPage) {
              this.actQuery.page = 0;
            }
            this.activityList = activity.data;
            console.log(this.activityList);
          } else {
            this.actQuery.page = this.actQuery.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    clockListData() {
      let query = {
        page:this.query.page,
        admin_type:0,
      }
      $http.post("plugin.check-in-rebate.frontend.participate-in.get-participateIn-list", query, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            this.isLoadMore = true;
            this.totalPage = res.last_page;
            if (!this.totalPage) {
              this.query.page = 0;
            }
            this.clockList = res.data;
            console.log(this.clockList);
          } else {
            this.query.page = this.query.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    getMoreData() {
      if(this.active == 0 && this.isAdmin) {
        this.actMoreData();
      } else {
        this.partMoreData();
      }
    },
    partMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.query.page >= this.totalPage) {
        return;
      } else {
        this.query.page  = this.query.page+1;
        let query = {
          page:this.query.page,
          admin_type:0,
        }
        $http.get("plugin.check-in-rebate.frontend.participate-in.get-participateIn-list", query, "正在获取").then(
          response => {
            if (response.result == 1) {
              let res = response.data;
              let list = res.data;
              this.isLoadMore = true;
              this.clockList = [...this.clockList, ...list];
            } else {
              this.query.page = this.query.page - 1;
              this.isLoadMore = false;
              this.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // console.log(response);
            // error callback
          }
        );
      }
    },
    actMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.actQuery.page >= this.actTotalPage) {
        return;
      } else {
        this.actQuery.page  = this.actQuery.page+1;
        $http.post("plugin.check-in-rebate.frontend.index.get-base-info", {search:this.actQuery}, "正在获取").then(
          response => {
            if (response.result == 1) {
              let res = response.data;
              let {activity,set} = res;
              let list = activity.data;
              this.isLoadMore = true;
              this.activityList = [...this.activityList, ...list];
            } else {
              this.actQuery.page = this.actQuery.page - 1;
              this.isLoadMore = false;
              this.$dialog.alert({ message: response.msg });
            }
          },
          function(response) {
            // console.log(response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.memberTab = [
      {
        name:'参与的',
        val:0
      }
    ];
    let yz_basic_info = JSON.parse(localStorage.getItem("yz_basic_info"));
    this.imgPath = yz_basic_info.host;
    if (yz_basic_info.plugin_setting?.check_in_rebate?.plugin_name){
      this.pluginName = yz_basic_info.plugin_setting?.check_in_rebate?.plugin_name;
      this.fun.setWXTitle(this.pluginName || '消费商品打卡返还');
    }
    
    this.query.page = 1;
    this.clockList = [];
    this.getMember();
    this.clockListData();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}